//
//  BIDSettingViewController.m
//  cxgov
//
//  Created by mal on 16/3/16.
//  Copyright © 2016年 mal. All rights reserved.
//

#import "BIDSettingViewController.h"
#import "BIDSettingCell.h"
#import "BIDSetPasswordViewController.h"
#import "BIDFeedbackViewController.h"
#import "BIDSetThemeViewController.h"
#import "BIDSetFontSizeViewController.h"
#import "BIDLoginViewController.h"
#import "BIDVersionViewController.h"

@interface BIDSettingViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    NSArray *_dataSourceArr;
    BOOL _bRegister;
}
@end

@implementation BIDSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"系统设置";
    // Do any additional setup after loading the view from its nib.
    //
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _dataSourceArr = @[@{@"imgName":@"setting_password.png", @"title":@"修改密码"},
                       @{@"imgName":@"setting_feedback.png", @"title":@"意见反馈"},
                       @{@"imgName":@"setting_version.png", @"title":@"版本更新"},
                       @{@"imgName":@"setting_exit.png", @"title":@"退出登录"}];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSourceArr.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    NSUInteger row = indexPath.row;
    NSUInteger section = indexPath.section;
    static NSString *identifier = @"identfier";
    if(!_bRegister)
    {
        _bRegister = YES;
        UINib *nib = [UINib nibWithNibName:@"BIDSettingCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:identifier];
    }
    BIDSettingCell *settingCell = [tableView dequeueReusableCellWithIdentifier:identifier];
    NSDictionary *dic = _dataSourceArr[row];
    settingCell.imgView.image = [UIImage imageNamed:dic[@"imgName"]];
    settingCell.titleLabel.text = dic[@"title"];
    cell = settingCell;
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40.f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UIViewController *vc = nil;
    switch(indexPath.row)
    {
        case 0:
        {
            //修改密码
            vc = [[BIDSetPasswordViewController alloc] initWithNibName:@"BIDSetPasswordViewController" bundle:nil];
        }
            break;
        case 1:
        {
            //意见反馈
            vc = [[BIDFeedbackViewController alloc] initWithNibName:@"BIDFeedbackViewController" bundle:nil];
        }
            break;
        case 2:
        {
            //版本更新
            vc = [[BIDVersionViewController alloc] initWithNibName:@"BIDVersionViewController" bundle:nil];
        }
            break;
        case 3:
        {
            //退出登录
            if(IPHONE4OR4S)
            {
                vc = [[BIDLoginViewController alloc] initWithNibName:@"BIDLoginViewController2" bundle:nil];
            }
            else
            {
                vc = [[BIDLoginViewController alloc] initWithNibName:@"BIDLoginViewController" bundle:nil];
            }
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:@"" forKey:@"username"];
            [defaults setObject:@"" forKey:@"password"];
            [defaults synchronize];
            [self.navigationController setViewControllers:@[vc]];
            return;
        }
            break;
    }
    [self.navigationController pushViewController:vc animated:YES];
}

@end
